package com.china08.yxyapi.api.manage.stu.mystudy.huixue.scoreimprove;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.huixue.YxyHuixuePlan;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.huixue.YxyHuixuePlanRepository;

import io.swagger.annotations.ApiOperation;

/**
 * 成绩提升--计划列表--查看--确认
 */
@CrossOrigin
@RestController
public class YxyHuixuePlanUpdController extends YxyApiBaseController {
    @Autowired
    private YxyHuixuePlanRepository yxyHuixuePlanRepository;

    @ApiOperation(value = "成绩提升首页 计划列表--查看--确认")
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/stu/mystudy/huixue/scoreimprove/upd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {

        YxyHuixuePlan yxyHuixuePlan = yxyHuixuePlanRepository.findOne(reqModel.id);
        yxyHuixuePlan.setCurrentScore(reqModel.currentScore);
        yxyHuixuePlanRepository.save(yxyHuixuePlan);
        RespModel respModel = new RespModel();
        YxyHuixuePlan yxyHuixuePlanupdate = yxyHuixuePlanRepository.findOne(reqModel.id);
        if (yxyHuixuePlanupdate != null && yxyHuixuePlanupdate.getCurrentScore() != -1) {
            respModel.result = "添加分数成功";
        } else {
            respModel.result = "添加分数失败";
        }
        return respModel;
    }

    protected static class ReqModel extends YxyApiReqModel {

        public String id;// 计划id

        public Double currentScore;// 本次考试成绩

    }

    protected static class RespModel extends YxyApiRespModel {

        public String result;// 结果

    }

}
